package com.elvin.wx.controller;


import com.elvin.wx.beans.WireDevWarm;
import com.elvin.wx.service.WireDevPoliceService;
import com.elvin.wx.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 无线设备报警数据 前端控制器
 * </p>
 *
 * @author zhenchl
 * @since 2022-01-14
 */

@Controller
@RestController
@RequestMapping("/wireDevPolice")
@Log4j2
@Api("无线设备报警数据管理")
@ApiIgnore
//不要了，暂时不显示，防止以后又要
public class WireDevPoliceController {

    @Resource
    private WireDevPoliceService service;

    @ApiOperation(value = "获取所有无线设备报警数据")
    @PostMapping("/queryAll")
    public Result<Object> queryAll() {
        Result<Object> result = new Result<>();
        try {
            List<WireDevWarm> selectList = service.selectList(null);
            result.success(selectList);
        } catch (Exception e) {
            log.debug(e.getMessage());
            result.fail(null, e.getMessage());
        }
        return result;
    }

    @ApiOperation(value = "新增无线设备报警数据")
    @PostMapping("/insert")
    public Result<Object> insert(@RequestBody WireDevWarm entity) {
        Result<Object> result = new Result<>();
        try {
            service.insert(entity);
            result.success(entity, "新增成功");
        } catch (Exception e) {
            log.debug(e.getMessage());
            result.fail(null, e.getMessage());
        }
        return result;
    }

    @ApiOperation(value = "修改无线设备报警数据")
    @PostMapping("/update")
    public Result<Object> update(@RequestBody WireDevWarm entity) {
        Result<Object> result = new Result<>();
        try {
            service.updateById(entity);
            result.success("修改成功");
        } catch (Exception e) {
            log.debug(e.getMessage());
            result.fail(null, e.getMessage());
        }
        return result;
    }

    @ApiOperation(value = "删除无线设备报警数据 ")
    @PostMapping("/delete")
    public Result<Object> delete(@ApiParam("无线设备报警数据id") @RequestParam("id") Long id) {
        Result<Object> result = new Result<>();
        try {
            service.deleteById(id);
            result.success("删除成功");
        } catch (Exception e) {
            log.debug(e.getMessage());
            result.fail(null, e.getMessage());
        }
        return result;
    }

    @ApiOperation(value = "根据ID获取无线设备报警数据")
    @PostMapping("/getById")
    public Result<Object> getById(@ApiParam("无线设备报警数据id") @RequestParam("id") Long id) {
        Result<Object> result = new Result<>();
        try {
            WireDevWarm entity = new WireDevWarm();
            entity.setId(id);
            entity = service.selectById(entity);
            result.success(entity);
        } catch (Exception e) {
            log.debug(e.getMessage());
            result.fail(null, e.getMessage());
        }
        return result;
    }

    @ApiOperation(value = "根据ID获取无线设备报警数据")
    @PostMapping("/getByProAndDevId")
    public Result<Object> getByProAndDevId(@RequestParam("pro_id") String pro_id,@RequestParam("dev_id") String dev_id) {
        Result<Object> result = new Result<>();
        try {
            WireDevWarm entity = new WireDevWarm();
            entity.setProId(pro_id);
            entity.setDevId(dev_id);
            entity = service.getByProAndDevId(entity);
            result.success(entity);
        } catch (Exception e) {
            log.debug(e.getMessage());
            result.fail(null, e.getMessage());
        }
        return result;
    }
}

